with f as (
  select
        id                                
       ,work_order_code                   
       ,apply_name                        
       ,apply_contact_information         
       ,waybill_no                        
       ,operation_type_id                 
       ,operation_type_name               
       ,problem_piece_id                  
       ,problem_piece_code                
       ,problem_type_id                   
       ,problem_type_code                 
       ,problem_type_name                 
       ,problem_type_subject_id           
       ,problem_type_subject_code         
       ,problem_type_subject_name         
       ,problem_description               
       ,apply_cancel_reason               
       ,proof_attachment                  
       ,customer_code                     
       ,customer_name                     
       ,problem_piece_attachment          
       ,penalty_amount                    
       ,award_amount                      
       ,subsidy_amount                    
       ,handling_fee                      
       ,work_order_status                 
       ,work_order_source                 
       ,apply_review_flag                 
       ,responsible_review_flag           
       ,intervention_flag                 
       ,appeal_flag                       
       ,create_by                         
       ,update_by                         
       ,create_by_name                    
       ,update_by_name                    
       ,status_update_time                
       ,create_time                       
       ,update_time                       
       ,is_enable                         
       ,is_delete                         
       ,finish_time                       
       ,finish_type                       
       ,subsidy_flow_flag                 
       ,flow_flag                         
       ,video_attachment                  
       ,apply_network_id                  
       ,apply_network_code                
       ,apply_network_name                
       ,apply_proxy_id                    
       ,apply_proxy_code                  
       ,apply_proxy_name                  
       ,resp_network_id                   
       ,resp_network_code                 
       ,resp_network_name                 
       ,resp_proxy_id                     
       ,resp_proxy_code                   
       ,resp_proxy_name                   
       ,penalty_network_id                
       ,penalty_network_code              
       ,penalty_network_name              
       ,award_network_id                  
       ,award_network_code                
       ,award_network_name                
       ,subsidy_network_id                
       ,subsidy_network_code              
       ,subsidy_network_name              
       ,fee_network_id                    
       ,fee_network_code                  
       ,fee_network_name                  
       ,apply_center_id                   
       ,apply_center_code                 
       ,apply_center_name                 
       ,resp_center_id                    
       ,resp_center_code                  
       ,resp_center_name                  
       ,resp_flag                         
       ,modification_frequency            
       ,proof_video_attachment            
       ,old_problem_type_code             
       ,old_problem_type_name             
       ,old_problem_type_subject_code     
       ,old_problem_type_subject_name     
       ,registration_time                 
       ,row_number() over(partition by waybill_no order by update_time desc) as rank
  from jms_ods.problem_express_wo
    where dt between date_sub('{{ execution_date | cst_ds }}',60)
         and date_add('{{ execution_date | cst_ds }}',60)
             and date(create_time) between date_sub('{{ execution_date | cst_ds }}',60)
             and '{{ execution_date | cst_ds }}'
)
insert overwrite table jms_dwd.dwd_problem_express_wo_dt partition(dt)
  select
        id                                
       ,work_order_code                   
       ,apply_name                        
       ,apply_contact_information         
       ,waybill_no                        
       ,operation_type_id                 
       ,operation_type_name               
       ,problem_piece_id                  
       ,problem_piece_code                
       ,problem_type_id                   
       ,problem_type_code                 
       ,problem_type_name                 
       ,problem_type_subject_id           
       ,problem_type_subject_code         
       ,problem_type_subject_name         
       ,problem_description               
       ,apply_cancel_reason               
       ,proof_attachment                  
       ,customer_code                     
       ,customer_name                     
       ,problem_piece_attachment          
       ,penalty_amount                    
       ,award_amount                      
       ,subsidy_amount                    
       ,handling_fee                      
       ,work_order_status                 
       ,work_order_source                 
       ,apply_review_flag                 
       ,responsible_review_flag           
       ,intervention_flag                 
       ,appeal_flag                       
       ,create_by                         
       ,update_by                         
       ,create_by_name                    
       ,update_by_name                    
       ,status_update_time                
       ,create_time                       
       ,update_time                       
       ,is_enable                         
       ,is_delete                         
       ,finish_time                       
       ,finish_type                       
       ,subsidy_flow_flag                 
       ,flow_flag                         
       ,video_attachment                  
       ,apply_network_id                  
       ,apply_network_code                
       ,apply_network_name                
       ,apply_proxy_id                    
       ,apply_proxy_code                  
       ,apply_proxy_name                  
       ,resp_network_id                   
       ,resp_network_code                 
       ,resp_network_name                 
       ,resp_proxy_id                     
       ,resp_proxy_code                   
       ,resp_proxy_name                   
       ,penalty_network_id                
       ,penalty_network_code              
       ,penalty_network_name              
       ,award_network_id                  
       ,award_network_code                
       ,award_network_name                
       ,subsidy_network_id                
       ,subsidy_network_code              
       ,subsidy_network_name              
       ,fee_network_id                    
       ,fee_network_code                  
       ,fee_network_name                  
       ,apply_center_id                   
       ,apply_center_code                 
       ,apply_center_name                 
       ,resp_center_id                    
       ,resp_center_code                  
       ,resp_center_name                  
       ,resp_flag                         
       ,modification_frequency            
       ,proof_video_attachment            
       ,old_problem_type_code             
       ,old_problem_type_name             
       ,old_problem_type_subject_code     
       ,old_problem_type_subject_name     
       ,registration_time                 
       ,date(create_time) as dt
 from f
   where rank = 1
          distribute by pmod(id,8) ;
